package function;

public class Division extends Function {
	Function f1;
	Power f2;

	public Division(Function f_1, Power f_2) {
		f1 = f_1;
		f2 = f_2;
	}

	public Function getF1() {
		return f1;
	}

	public void setF1(Function f1) {
		this.f1 = f1;
	}

	public Power getF2() {
		return f2;
	}

	public void setF2(Power f2) {
		this.f2 = f2;
	}

	public double evaluate(double x) {
		return f1.evaluate(x) / f2.evaluate(x);
	}

	public Function differentiate() {
		Function f = new ADD(new Multiply(f1.differentiate(), f2),
				new Multiply(f2.differentiate(), f1).invert());
		return new Division(f, new Power(f2, new Power(f2.getExponent(),
				new Constant(2))));
	}

	public String toString() {
		return "(" + f1.toString() + "/" + f2.toString() + ")";
	}
}
